package com.semanticweb.webapp.model.rbac;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

@Entity
@Table(name = "roles")
public class Role extends AbstractPersistedEntity {

	private static final long serialVersionUID = 122637142363581597L;

	@NotNull
	private String roleName;
	public static final String ROLE_NAME = "roleName";

	@Version
	@Column(name = "version")
	private Integer version;

	@ManyToMany(cascade = CascadeType.ALL)
	private Set<User> users = new HashSet<User>();

	@ManyToMany(cascade = CascadeType.ALL)
	private Set<Permission> permissions = new HashSet<Permission>();

	public Integer getVersion() {
		return this.version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public String toString() {
		return ReflectionToStringBuilder.toString(this,
				ToStringStyle.SHORT_PREFIX_STYLE);
	}

	public String getRoleName() {
		return this.roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public Set<User> getUsers() {
		return this.users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}

	public Set<Permission> getPermissions() {
		return this.permissions;
	}

	public void setPermissions(Set<Permission> permissions) {
		this.permissions = permissions;
	}
}
